package cn.edu.jxau.test;

public class Main {

    public static void main(String[] args) {
        
        int[] arr1 = {0,1,2,3,4,5,6,7,8,9};
        System.out.println(isMinHeap(arr1));
    }

    /**
     * 判断arr是否是一个小顶堆
     * 
     * @param arr
     * @return
     */
    private static boolean isMinHeap(int[] arr) {

        for (int i = 1; i <= arr.length / 2; i++) {
            if (2 * i < arr.length) {
                if (arr[i] > arr[2 * i]) {
                    return false;
                }
            }
            if (2 * i + 1 < arr.length) {
                if (arr[i] > arr[2 * i + 1]) {
                    return false;
                }
            }
        }
        return true;
    }
}
